package com.qwt.part_time_api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qwt.part_time_api.mapper.NewsMapper;
import com.qwt.part_time_api.pojo.News;
import com.qwt.part_time_api.service.NewsService;
import com.qwt.part_time_api.vo.Result;
import com.qwt.part_time_api.vo.params.PageParams;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author 君子慎独
 * @create 2021/12/24 0024 19:49
 */

@Service
@Slf4j
public class NewsServiceImpl implements NewsService {

    @Autowired
    private NewsMapper newsMapper;

    @Override
    public Result findNewsByType(PageParams params) {
        log.info("获取新闻公告");
        Page<News> page = new Page<>(params.getPage(), params.getPageSize());

        LambdaQueryWrapper<News> wrapper = new LambdaQueryWrapper<>();

        wrapper.eq(News::getType, params.getNewsType());

        Page<News> newsPage = newsMapper.selectPage(page, wrapper);

        return Result.success(newsPage);
    }
}
